﻿using System.Collections.Generic;
namespace HBase {
    /**
   *┌────────────────────────────────────────────────┐
   *│　描    述：MyDict                                                    
   *│　作    者：sgj                                              
   *│　版    本：1.0                                              
   *│　创建时间：2021/4/12 9:32:25                        
   *└────────────────────────────────────────────────┘
   **/
    public class MyDictList<K, V> :Dictionary<K ,List<V>> {


        public void remove(K k) {
            lock( this ) {
                if( this.ContainsKey(k) ) {
                    this.Remove(k);
                }
            }

        }
        public void remove(V v) {
            lock( this ) {
                foreach( var vals in this.Values ) {
                    if( vals.Contains(v) ) {
                        vals.Remove(v);
                        return;
                    }
                }
            }

        }
        public void removeAll(V v) {
            lock( this ) {
                foreach( var vals in this.Values ) {
                    if( vals.Contains(v) ) {
                        vals.Remove(v);

                    }
                }
            }

        }

        public List<V> getList(K k) {
            lock( this ) {
                if( this.ContainsKey(k) ) {
                    return this[k];
                } else {
                    List<V> list = new List<V>();
                    this.Add(k ,list);
                    return list;
                }
            }
        }
        public V getLast(K k) {
            lock( this ) {
                if( this.ContainsKey(k) ) {
                    List<V> l = this[k];
                    int c = l.Count;
                    if( c > 0 ) {
                        return l[c - 1];

                    }
                }
            }

            return default(V);

        }

        public void add(K k ,V v) {
            lock( this ) {

                if( this.ContainsKey(k) ) {
                    this[k].Add(v);
                } else {
                    List<V> list = new List<V>();
                    this.Add(k ,list);
                    list.Add(v);
                }

            }
        }


    }
}
